/*************************************************************************
 * 文件名称：
 * 作    者：Smile
 * 创建时间：2023-10-18 11:51:14
 * 模块名称：
 * 主要函数：
 * 版    本：1.0
 * 修改记录：
 * 1.0->
	 * 初始化代码
 * 1.2->
	 *
 ************************************************************************/
#include "WLog4cplus.h"


void WLog4cplus::test()
{
	LOG4CPLUS_TRACE(logger, "printMessages()");
	LOG4CPLUS_DEBUG(logger, "This is a DEBUG message");
	LOG4CPLUS_INFO(logger, "This is a INFO message");
	LOG4CPLUS_WARN(logger, "This is a WARN message");
	LOG4CPLUS_ERROR(logger, "This is a ERROR message");
	LOG4CPLUS_FATAL(logger, "This is a FATAL message");
}

void WLog4cplus::trace(const char * msg)
{
	LOG4CPLUS_TRACE(logger, msg);
}

void WLog4cplus::debug(const char * msg)
{
	LOG4CPLUS_DEBUG(logger, msg);
}
void WLog4cplus::info(const char * msg)
{
	LOG4CPLUS_INFO(logger, msg);
}
void WLog4cplus::warn(const char * msg)
{
	LOG4CPLUS_WARN(logger, msg);
}
void WLog4cplus::error(const char * msg)
{
	LOG4CPLUS_ERROR(logger, msg);
}
void WLog4cplus::fatal(const char * msg)
{
	LOG4CPLUS_FATAL(logger, msg);
}

void WLog4cplus::tracemsg(const char * msg, const char * filename, int line, const char * function)
{
	char info[4096] = { 0 };
	sprintf(info, "%s %d %s:-->%s", filename, line, function, msg);
	LOG4CPLUS_TRACE(logger, info);
}
void WLog4cplus::debugmsg(const char * msg, const char * filename, int line, const char * function)
{
	char info[4096] = { 0 };
	sprintf(info, "%s %d %s:-->%s", filename, line, function, msg);
	LOG4CPLUS_DEBUG(logger, info);
}
void WLog4cplus::infomsg(const char * msg, const char * filename, int line, const char * function)
{
	char info[4096] = { 0 };
	sprintf(info, "%s %d %s:-->%s", filename, line, function, msg);
	LOG4CPLUS_INFO(logger, info);
}
void WLog4cplus::warnmsg(const char * msg, const char * filename, int line, const char * function)
{
	char info[4096] = { 0 };
	sprintf(info, "%s %d %s:-->%s", filename, line, function, msg);
	LOG4CPLUS_WARN(logger, info);
}
void WLog4cplus::errormsg(const char * msg, const char * filename, int line, const char * function)
{
	char info[4096] = { 0 };
	sprintf(info, "%s %d %s:-->%s", filename, line, function, msg);
	LOG4CPLUS_ERROR(logger, info);
}
void WLog4cplus::fatalmsg(const char * msg, const char * filename, int line, const char * function)
{
	char info[4096] = { 0 };
	sprintf(info, "%s %d %s:-->%s", filename, line, function, msg);
	LOG4CPLUS_FATAL(logger, info);
}



WLog4cplus::WLog4cplus()
{
	// 初始化 log4cplus 系统
	log4cplus::Initializer initializer;

	// 获取日志记录器  Smile 日志的名称
    logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("Smile"));
    log4cplus::SharedAppenderPtr consoleAppender(new log4cplus::ConsoleAppender);
	consoleAppender->setLayout(std::make_unique<log4cplus::PatternLayout>(LOG4CPLUS_TEXT("%D{%Y-%m-%d %H:%M:%S} %-5p %c{2} - %m%n")));
	logger.addAppender(consoleAppender);

	// 添加文件输出
	log4cplus::SharedAppenderPtr fileAppender(new log4cplus::RollingFileAppender(LOG4CPLUS_TEXT("app.log")));
	fileAppender->setLayout(std::make_unique<log4cplus::PatternLayout>(LOG4CPLUS_TEXT("%D{%Y-%m-%d %H:%M:%S} %-5p %c{2} - %m%n")));
	logger.addAppender(fileAppender);
}


WLog4cplus::~WLog4cplus()
{

}

